/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-11-27     Administrator       the first version
 */
#ifndef APPLICATIONS_ACTIONQUEUE_ACTION_QUEUE_H_
#define APPLICATIONS_ACTION_QUEUE_ACTION_QUEUE_H_

#include <rtdef.h>

#ifdef __cplusplus
extern "C" {
#endif


#define MOTOR_FUNC 1
#define PUMP_FUNC 1

enum
{
MOTOR = 50,
PUMP = 51,

};


enum
{
  MODE_SLAVE,
  MODE_AUTO
};

enum
{
MODE_POS,
SW_MODE,
TIME_MODE,
RESET_MODE,
MODE_AD_POS,
ADVANCED_DIS_MODE
};

typedef struct
{
    rt_uint32_t time;
    rt_uint8_t sw;
}MODE_TIME;

typedef struct
{
    rt_uint8_t speedSelect;
    rt_uint8_t posNo;
}MODE_ADVANCED_POS;

typedef struct
{
    rt_uint8_t speedSelect;
    rt_uint8_t distance;
}MODE_ADVANCED_DIST;

typedef union
{
    rt_uint8_t posNo;
    rt_uint8_t sw;
    MODE_TIME mode_time;
    MODE_ADVANCED_POS ad_pos;
    rt_uint32_t distance;
    MODE_ADVANCED_DIST ad_dis;
}ACT_INFO;

typedef struct Action_Queue
{
    rt_uint8_t devType;
    rt_uint8_t devNo;
    rt_uint8_t actMode;
    ACT_INFO actInfo;
    struct Action_Queue *next;
}Action_Queue;

typedef struct Action
{
    rt_uint8_t devType;
    rt_uint8_t devNo;
    rt_uint8_t actMode;
    ACT_INFO actInfo;
}Action;

class ActionQueue
{
private:
    Action_Queue* headNode;
    Action_Queue* tailNode;
    rt_uint8_t Mode;
    rt_uint32_t Total;
    rt_uint8_t No;
public:
    ActionQueue();
    virtual ~ActionQueue();
public:
    struct Action_Queue* CreatActionQueue(void *parameter);
    struct Action_Queue* TailInsertActionQueue(Action_Queue temp,Action_Queue* tail);
    struct Action_Queue* DeleteHeadNode(Action_Queue* headNode);
    void CreatActionQueueTask(Action action);
    void AddActionQueueTask(Action action);
    void actionActProcess(void *parameter);
    void AddTaskToMotor(rt_uint8_t devNo,rt_uint8_t Mode);
    void StartPosMode(rt_uint8_t devNo,ACT_INFO ActInfo);
    void ActOneStep();
    void NextStep();
    void Process(void *parameter);
};

extern ActionQueue ActQueue[50];


void Act_Q1_Task(void *parameter);

#ifdef __cplusplus
}
#endif


#endif /* APPLICATIONS_ACTIONQUEUE_ACTION_QUEUE_H_ */
